package com.hb.trade.server.project.section.service.status;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hb.core.pojo.enums.SectionStatusEnum;
import com.hb.core.pojo.project.opening.entity.OpeningBidInfo;
import com.hb.core.pojo.project.section.dto.BidSectionDTO;
import com.hb.trade.server.project.opening.service.OpeningBidHallService;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 开标中判断逻辑
 *
 * @author zhaojk
 */
@Setter
@Getter
@Service
public class BidOpening implements CalSectionStatus {

    /**
     * 当前逻辑的标段状态
     */
    private final static SectionStatusEnum SECTION_STATUS = SectionStatusEnum.BID_OPENING;

    private static List<Integer> bidOpenStatus = CollUtil.list(false);
    static {
        //0:未开标 1:签到 2:开标 3:解密 4:解密结束 5:唱标 6:确认 7:结束 8:流标
        bidOpenStatus.add(1);
        bidOpenStatus.add(2);
        bidOpenStatus.add(3);
        bidOpenStatus.add(4);
        bidOpenStatus.add(5);
        bidOpenStatus.add(6);
    }
    /**
     * 排序号
     */
    private Integer sortCode = SECTION_STATUS.getCode();

    private final OpeningBidHallService openingBidHallService;

    public BidOpening(OpeningBidHallService openingBidHallService) {
        this.openingBidHallService = openingBidHallService;
    }


    @Override
    public Long getSectionStatus(BidSectionDTO section) {
        // 查询开标信息
        QueryWrapper<OpeningBidInfo> wrapper = OpeningBidInfo.wrapper("status");
        wrapper.eq("section_id", section.getId()).last("limit 1");
        OpeningBidInfo openingBidInfo = openingBidHallService.getOne(wrapper);
        if (openingBidInfo == null){
            return null;
        }
        return SECTION_STATUS.getId();

        // 当前标段的审核状态
/*        Integer status = openingBidInfo.getStatus();
        if (CollUtil.contains(bidOpenStatus,status)) {
            return SECTION_STATUS.getId();
        }
        return null;*/
    }

    @Override
    public Integer getSort() {
        return sortCode;
    }
}
